//related to picker3.ui
var page = sm("do_Page");
var app = sm("do_App");
var storage = sm("do_Storage");
var nf = sm("do_Notification");
var root = ui("$");
var urlUser = require("url/user");
var qqHttp = require("helper/http");

//遮罩显示
var animMaskShow = mm("do_Animator");
var propsMS = {bgColor:"00000077"};
animMaskShow.append(360,propsMS,"EaseOut");
//面板显示
var animPanelShow = mm("do_Animator");
var propsPS = {y:460};
animPanelShow.append(360,propsPS,"EaseOut");
//遮罩隐藏
var animMaskHide = mm("do_Animator");
var propsMH = {bgColor:"00000000"};
animMaskHide.append(360,propsMH,"EaseIn");
//面板隐藏
var animPanelHide = mm("do_Animator");
var propsPH = {y:960};
animPanelHide.append(360,propsPH,"EaseIn");

//picker
var labtit = ui("do_Label_2");
var pickerbg = ui("pickerbg");//遮罩
var pickerbox = ui("do_ALayout_1");

var interests = [{"name":"足球","selected":0,"bgColor":"00000000","val":8},{"name":"篮球","selected":0,"bgColor":"00000000","val":10},{"name":"排球","selected":0,"bgColor":"00000000","val":11},
                 {"name":"羽毛球","selected":0,"bgColor":"00000000","val":21}, {"name":"跑步","selected":0,"bgColor":"00000000","val":20},
             {"name":"游泳","selected":0,"bgColor":"00000000","val":12},{"name":"摄影","selected":0,"bgColor":"00000000","val":14},
             {"name":"游戏","selected":0,"bgColor":"00000000","val":16},{"name":"电影","selected":0,"bgColor":"00000000","val":18},
             {"name":"旅游","selected":0,"bgColor":"00000000","val":22}, {"name":"健身","selected":0,"bgColor":"00000000","val":23},{"name":"其他","selected":0,"bgColor":"00000000","val":24}]; 
var interestGrids = mm("do_ListData");
var do_GridView_interest = ui("do_GridView_interest");
interestGrids.addData(interests);
do_GridView_interest.bindItems(interestGrids);

page.on("interests",function(data){
	pickerbg.visible = true;
	pickerbg.animate(animMaskShow);
	pickerbox.animate(animPanelShow);
})

//初始化
page.on("getInterests",function(data){
	var strSelect="";
	var arraySelect=[];
	var data_temp = interestGrids.getRange(0);
	for (var i = 0; i < data_temp.length; i++) {
		if(data.initSelect && data.initSelect.indexOf(data_temp[i].name) >= 0){
			interestGrids.updateOne(i, {"name":data_temp[i].name,"selected":1,"bgColor":"00000000"});	
		}else{
			interestGrids.updateOne(i, {"name":data_temp[i].name,"selected":0,"bgColor":"00000000"});	
		}
	}
	do_GridView_interest.refreshItems();

})


//遮罩事件
pickerbg.on("touch","",300,function(){
	pickerbox.animate(animPanelHide);
	pickerbg.animate(animMaskHide,function(){
		pickerbg.visible = false;
	});
});

//防穿透
pickerbox.on("touch",function(){})
ui("do_Button_1").on("touch", function(data) {
	var param= {};
	param.interests = "";
	pickerbox.animate(animPanelHide);
	pickerbg.animate(animMaskHide,function(){
		pickerbg.visible = false;
	});
	page.fire("refreshInterest",param);
})
//订阅GridView的touch点击事件
do_GridView_interest.on("touch", function(data) {
	var param= {};
	var data_temp = interestGrids.getRange(0);
	var strSelect=data_temp[data].name;
	param.interests = strSelect;
	
	pickerbox.animate(animPanelHide);
	pickerbg.animate(animMaskHide,function(){
		pickerbg.visible = false;
	});
	
	page.fire("refreshInterest",param);
})